//
//  LKBaseViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/4/9.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKBaseViewController.h"
#import "YLPushViewModel.h"
@implementation LKNavBackButton

- (void)setTitleColor:(UIColor *)titleColor
{
    _titleColor = titleColor;
    [self setTitleColor:titleColor forState:UIControlStateNormal];
}

+ (instancetype)navBackButton
{
    LKNavBackButton *button = [[LKNavBackButton alloc] init];
    [button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button setTitle:@" 返回" forState:UIControlStateNormal];
    [button setTitleColor:blueDefault forState:UIControlStateNormal];
    button.bounds = CGRectMake(0, 0, 70, 30);
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    return button;
}

- (void)setType:(NSInteger)type
{
    _type = type;
    if (type == 1) {
        [self setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    } else {
        [self setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    }
}

@end





@interface LKBaseViewController ()<UINavigationControllerDelegate>
@property (nonatomic, strong) NSMutableDictionary *heightAtIndexPath;//缓存高度
@property(nonatomic,assign) BOOL pushing;
@end

@implementation LKBaseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = cellHeaderBgColor;
    [self setNavgationBackBtn];
    if (@available(iOS 11.0, *)) {
        [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}
-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}
/**
 设置返回按钮样式
 */
-(void)setNavgationBackBtn{
   self.backButton  = [LKNavBackButton navBackButton];
    [_backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backButton];
}

- (void)back
{
    NSArray *viewcontrollers = self.navigationController.viewControllers;
    if (viewcontrollers.count > 1) {
        if ([viewcontrollers objectAtIndex:viewcontrollers.count - 1] == self) {
            //push方式
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else{
        //present方式
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

-(NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
    NSString * text = @"暂时还没有相关数据!";
    
    NSDictionary * attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f ],
        NSForegroundColorAttributeName:[UIColor lightGrayColor]};
    
    return [[ NSAttributedString  alloc ] initWithString:text attributes:attributes];
}
-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return [UIImage imageNamed:@"nodata"];
}
-(CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
    return 0;
}
-(void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view{
    
    NSLog(@"点击了空白页");

}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
/**
 获取用户详情
 */
-(void)getAccountDetailInformation{
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:UserDetailUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {

    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        LKUserInfor *userInfor = [LKUserInfor accountWithDict:responseObject[@"result"]];
        userInfor.token = [LKUserInforTool account].token;
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:userAccountCaculationUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {

        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            NSString *customerCout = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"cusertomerCount"]];
            NSString *investMoney = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"orderInverstment"]];
            NSString *investFundMoney = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"orderInverstmentFund"]];
            userInfor.cusertomerCount = customerCout;
            userInfor.orderInverstment = investMoney;
            userInfor.orderInverstmentFund = investFundMoney;
            [LKUserInforTool saveAccount:userInfor];
            [YLPushViewModel setUpMyPushInfo];
        } failure:^(NSString * _Nullable errorMessage) {

        }];


    } failure:^(NSString * _Nullable errorMessage) {

    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
